package com.hunttown.mes.dao;

import com.hunttown.common.dao.base.BaseDao;
import com.hunttown.common.domain.Query;
import com.hunttown.mes.domain.MesSaleExpressDetail;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * created by wangjunfu on 2022-07-25 14:54:20
 */
@Repository
public class MesSaleExpressDetailDao extends BaseDao {
    private static final Logger logger = LoggerFactory.getLogger(MesSaleExpressDetailDao.class);

    public MesSaleExpressDetail insert(final MesSaleExpressDetail mesSaleExpressDetail) {
        insert("MesSaleExpressDetail.insert", mesSaleExpressDetail);
        return mesSaleExpressDetail;
    }

    public Boolean updateInfoById(final MesSaleExpressDetail mesSaleExpressDetail) {
        return update("MesSaleExpressDetail.updateInfoById", mesSaleExpressDetail) > 0;
    }

    public Boolean updateInfoByQuery(final Query query) {
        return update("MesSaleExpressDetail.updateInfoByQuery", query) > 0;
    }

    public MesSaleExpressDetail selectById(final Integer id, final Integer entId) {
        Query query = Query.noPage();
        query.put("id", id);
        query.put("entId", entId);
        return queryForObject("MesSaleExpressDetail.selectById", query);
    }

    public List<MesSaleExpressDetail> selectByQuery(final Query query) {
        return queryForList("MesSaleExpressDetail.selectByQuery", query);
    }

    public Long countByQuery(final Query query) {
        return queryForObject("MesSaleExpressDetail.countByQuery", query);
    }

    public Boolean deleteById(final Integer id, final Integer entId) {
        MesSaleExpressDetail mesSaleExpressDetail = new MesSaleExpressDetail();
        mesSaleExpressDetail.setDeleteFlag(1);
        mesSaleExpressDetail.setId(id);
        mesSaleExpressDetail.setEntId(entId);

        return update("MesSaleExpressDetail.updateInfoById", mesSaleExpressDetail) > 0;
    }

    //物理删除不可恢复，慎用！
    public Boolean deleteByIdForPhysical(final Integer id) {
        Query query = Query.noPage();
        query.put("id", id);
        return delete("MesSaleExpressDetail.deleteById", query) > 0;
    }

    //获取某个商品的总发货数
    public Long getProductSendCount(final Query query) {
        return queryForObject("MesSaleExpressDetail.selectProductSendCount", query);
    }
}